package com.njworkorder.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njworkorder.Entity.MonthExamine;
import com.njworkorder.Entity.Section;
import com.njworkorder.Entity.Workspace;
import com.njworkorder.Service.WorkspaceService;
import com.njworkorder.Mapper.WorkspaceMapper;
import com.njworkorder.Utils.NoCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
* @author iron
* @description 针对表【workspace】的数据库操作Service实现
* @createDate 2024-11-08 10:52:14
*/
@Service
public class WorkspaceServiceImpl extends MPJBaseServiceImpl<WorkspaceMapper, Workspace>
    implements WorkspaceService{

    @Override
    public String getUpToDateWorkspaceNo() {
        LambdaQueryWrapper<Workspace> wrapper = new LambdaQueryWrapper<Workspace>()
                .apply("1=1")
                .orderByDesc(Workspace::getWorkspaceNo).last("limit 1");
        List<Workspace> list = list(wrapper);

        String WorkspaceNo = "000001";
        if (!list.isEmpty()) {
            String s = list.getFirst().getWorkspaceNo().substring(6);
            WorkspaceNo = NoCode.getNoCode(s);
        }
        return WorkspaceNo;
    }

    @Async
    @Override
    public CompletableFuture<List<Workspace>> getAllWorkspace() {
        LambdaQueryWrapper<Workspace> wrapper = new LambdaQueryWrapper<Workspace>()
                .apply("1=1");
        return CompletableFuture.completedFuture(list(wrapper));
    }

//    @Async
//    @Override
//    public CompletableFuture<List<Workspace>> getJoinMEWorkspace(String time) {
//        MPJLambdaWrapper<Workspace> wrapper = new MPJLambdaWrapper<Workspace>()
//                .select(Workspace::getId)
//                .selectAs("ROUND(sum(t2.amount)/count(*), 2)", Workspace::getWorkspaceName)
//
//
//                .leftJoin(Section.class,Section::getWorkspaceId,Workspace::getId)
//                .rightJoin(MonthExamine.class,MonthExamine::getSectionId,Section::getId)
//
//                .likeRight(StringUtils.isNotEmpty(time),MonthExamine::getPublishTime, time)
//                .apply("1=1")
//                .groupBy(Workspace::getId);
//        return CompletableFuture.completedFuture(selectJoinList(Workspace.class,wrapper));
//    }


}




